import { getCategoryListAPI } from "@/api";
import { getBannerListAPI, getFloorListAPI } from "@/api";

const state = {
	categoryList: [],
	bannerList: [],
	floorList: [],
};

const mutations = {
	GETCategory(state, data) {
		state.categoryList = data;
	},
	GETBanner(state, data) {
		state.bannerList = data;
	},
	GETFloor(state, data) {
		state.floorList = data;
	},
};

const actions = {
	async getCategory({ commit, state, rootState }) {
		try {
			const res = await getCategoryListAPI();
			if (res.code === 200) {
				commit("GETCategory", res.data);
			}
		} catch (error) {
			console.log(error);
		}
	},
	async getBanner({ commit }) {
		const res = await getBannerListAPI();
		commit("GETBanner", res.data);
	},
	async getFloor({ commit }) {
		const res = await getFloorListAPI();
		commit("GETFloor", res.data);
	},
};

const getters = {};

export default {
	namespaced: true,
	state,
	mutations,
	actions,
	getters,
};
// 疑问：为什么是commit先执行，action后执行？
